package slidingWindow;

//https://leetcode.cn/problems/longest-substring-without-repeating-characters/description/
public class l_3 {
    public int lengthOfLongestSubstring(String s) {
        //不是单纯字母, 所以直接开ASCII表大小的哈希数组
        int[] hash = new int[128];
        char[] str = s.toCharArray();
        int n = s.length(), ans = 0;
        for(int left = 0, right = 0; right < n; ++right) {
            //遇到字符无脑加
            ++hash[str[right]];
            //判断这个字符有没有重复
            if(hash[str[right]] > 1) {
                //左指针无脑往右走
                while(hash[str[right]] > 1) --hash[str[left++]];
            }
            ans = Math.max(ans, right - left + 1);
        }
        return ans;
    }
}
